<?php

namespace api\game\controller;

use Aaa\game\model\GameModel;

class AdminIndexController extends \Aaa\game\controller\AdminIndexController {

    protected $baseField = [
        [
            'field' => 'id',
            'name' => 'ID',
        ],
        [
            'field' => 'name',
            'name' => '名称',
        ],
        [
            'field' => 'thumb',
            'name' => '图片',
            'type' => 'image',
        ],
        [
            'field' => 'status',
            'name' => '禁用',
            'type' => 'radio',
            'options' => [
                ['name' => '启用', 'value' => 1],
                ['name' => '禁用', 'value' => 0],
            ],
            'default' => 1,
        ],
        [
            'field' => 'device',
            'name' => '终端',
            'type' => 'radio',
            'options' => [
                ['name' => '端游', 'value' => 0],
                ['name' => '手游', 'value' => 1],
                ['name' => '其他', 'value' => 2],
            ],
        ],
        [
            'field' => 'os',
            'name' => '系统',
            'type' => 'radio',
            'options' => [
                ['name' => 'PC', 'value' => 0],
                ['name' => '苹果', 'value' => 1],
                ['name' => '安卓', 'value' => 2],
                ['name' => '互通', 'value' => 3],
            ],
        ],
        [
            'field' => 'is_hot',
            'name' => '热门',
            'type' => 'radio',
            'options' => [
                ['name' => '普通', 'value' => 0],
                ['name' => '热门', 'value' => 1],
            ],
            'default' => 0,
        ],
        [
            'field' => 'weight',
            'name' => '权重',
        ],
        [
            'field' => 'list_order',
            'name' => '排序',
        ],
    ];

    protected function beforeIndex() {
        $this->actionField = ['id', 'name', 'thumb', 'device', 'status', 'is_hot', 'weight', 'list_order',];
        $this->searchField = [
            'common' => [
                'id' => 'accurate',
                'name' => 'fuzzy',
                'device' => 'fuzzy',
                'status' => 'accurate',
                'is_hot' => 'accurate',
            ],
            'amount' => ['weight', 'list_order']
        ];
    }

    protected function beforeAdd() {
        $this->actionField = ['name', 'thumb', 'device', 'status', 'is_hot', 'weight', 'list_order',];
    }

    protected function beforeEdit() {
        $model = new GameModel;
        $model->id = $this->paramId();
        $level = $model->find()['level'];
        if ($level == 1) {
            $this->actionField = ['name', 'thumb', 'device', 'status', 'is_hot', 'weight', 'list_order',];
        } elseif ($level == 2) {
            $this->actionField = ['name',  'os',  'weight', 'list_order',];
        } else {
            $this->actionField = ['name', 'weight', 'list_order',];
        }
    }


}
